﻿using shenghua.Authorization;
using shenghua.Basics.MemberLevelSetting;
using shenghua.Member.Members;
using shenghua.Member.Members.Dto;
using shenghua.Member.ShippingAddresses;
using shenghua.Roles;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace shenghua.Tests.Member
{
    public class MemberTestBase : shenghuaTestBase
    {
        protected readonly IMemberAppService _memberAppService;
        private readonly IRoleAppService _roleAppService;
        private readonly IMemberLevelSettingAppService _memberLevelSettingAppService;

        public MemberTestBase()
        {
            _memberAppService = Resolve<IMemberAppService>();
            _roleAppService = Resolve<IRoleAppService>();
            _memberLevelSettingAppService = Resolve<IMemberLevelSettingAppService>();
        }

        public async Task<MemberDto> RegisterMember(string userName)
        {
            await _roleAppService.CreateMemberRole(new Roles.Dto.CreateRoleDto
            {
                Name = "Member",
                DisplayName = "Member",
                Permissions = new List<String> { "Member" }
            });

            await _memberLevelSettingAppService.Create(new Basics.MemberLevelSetting.Dto.CreateMemberLevelDto
            {
                Name = "普通会员",
                Discount = 1,
                DisplayName = "普通会员",
                NeededXPValue = 0,
                Roles = new List<string> { "Member" }
            });

            var member = await _memberAppService.Register(new shenghua.Member.Members.Dto.CreateMemberDto
            {
                UserName = userName,
                Password = "123456@Sh",
                EmailAddress = "982632988@qq.com",
                Name = "fkl",
                PhoneNumber = "18633904041"
            });

            return member;
        }
    }
}
